package com.github.bdeenyy.asv.service;

public class VectorCalculator {

    public static double[][] calculateVectors(double[] lengths, boolean isClockwise) {
        double[][] vectors = new double[3][2];

        double angle = 0;
        for (int i = 0; i < lengths.length; i++) {
            double radians = Math.toRadians(angle);
            vectors[i][0] = lengths[i] * Math.cos(radians);
            vectors[i][1] = lengths[i] * Math.sin(radians);

            angle += isClockwise ? -120 : 120;
        }

        return vectors;
    }

    public static double[] calculateResultantVector(double[][] vectors) {
        double resultX = 0;
        double resultY = 0;

        for (double[] vector : vectors) {
            resultX += vector[0];
            resultY += vector[1];
        }

        return new double[]{resultX, resultY};
    }
}
